﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using FastMapper.UnitTests.TestEntities;
using NUnit.Framework;
using FastMapper.Helpers;
using FluentAssertions;

namespace FastMapper.UnitTests.Helpers
{
    [TestFixture(Description = "Test Member Expressions Methods")]
    class MemberExpressionsExtensionsTests
    {
        [Test]
        public void GetMemberInfo_Works_Fine_With_Epression_With_Two_Levels()
        {
            Expression<Func<ClassA, string>> param = a => a.ComplexProperty1.Property4;
            var result = param.GetMemberInfoFromRoot();
            result.Name.Should().Be("ComplexProperty1");
            result.IsRoot.Should().BeTrue();
            result.Child.Name.Should().Be("Property4");
            result.Child.IsRoot.Should().BeFalse();

        }
        [Test]
        public void GetMemberInfo_Works_Fine_With_Epression_With_One_Level()
        {
            Expression<Func<ClassA, CLassC>> param = a => a.ComplexProperty1;
            var result = param.GetMemberInfoFromRoot();
            result.Name.Should().Be("ComplexProperty1");
            result.IsRoot.Should().BeTrue();
        }

        [Test]
        public void GetFullPath_Works_Fine()
        {
            var memberInfo = new MemberInfoNode();
            memberInfo.Name = "Prop1";
            memberInfo.AddChild(new MemberInfoNode{Name = "Prop2"});
            memberInfo.Child.AddChild(new MemberInfoNode{Name="Prop3"});
            var result = memberInfo.GetFullPath();
            result.Should().Be("Prop1.Prop2.Prop3");

        }
    }
}
